package com.canxin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.canxin.entity.BinduserEntity;
import com.canxin.entity.UserFocusEntity;
import com.canxin.service.BinduserServiceI;
import com.google.gson.Gson;

import net.sf.json.JSONObject;
import weixin.guanjia.account.service.WeixinAccountServiceI;
import weixin.guanjia.core.util.WeixinUtil;
import weixin.p3.oauth2.pojo.templateMsg.TemplateMsgPojo;
import weixin.p3.oauth2.rule.RemoteWeixinMethod;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.system.service.SystemService;

@Service("binduserService")
@Transactional
public class BinduserServiceImpl extends CommonServiceImpl implements BinduserServiceI {

	@Autowired
	private RemoteWeixinMethod remoteWeixinMethod;
	@Autowired
	private SystemService systemService;
	@Autowired
	private WeixinAccountServiceI weixinAccountService;
	
	@Override
	public List<BinduserEntity> getAllBindUser() {
		// TODO Auto-generated method stub
		return super.findHql("from BinduserEntity");
	}

	@Override
	public JSONObject getUserFocusInfo(String openid) {
		String tokenStr = weixinAccountService.getAccessToken("gh_d1ace5896840");
		String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="+tokenStr+"&openid="+openid;
		JSONObject resultJson  = WeixinUtil.httpRequest(url, "GET", "");
		org.jeecgframework.core.util.LogUtil.info(resultJson);
		return resultJson;
	}

	@Override
	public String getStudentIdByOpenId(String openid) {
		// TODO Auto-generated method stub
		BinduserEntity  bindUserEntity = (BinduserEntity) super.findHql("from BinduserEntity where openid=?",openid).get(0);
		return bindUserEntity.getStudentid();
	}
	
}